import { PipeTransform, ArgumentMetadata, BadRequestException } from '@nestjs/common'

export class ParseIntPipe implements PipeTransform<string, number> {
	transform(value: string, metadata: ArgumentMetadata): number {
		const val = parseInt(value, 10)
		if (isNaN(val)) {
			throw new BadRequestException('validate int failed')
		}
		return val
	}
}

